package cn.jumper.protection.controller;

import cn.jumper.protection.constant.Result;
import cn.jumper.protection.annotation.AccessLimit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 补充Controller
 * @author: jumper Hou
 * @create: 2023-4-6 15:13:46
 **/
@RestController
@RequestMapping("/pass")
@Slf4j
@AccessLimit(second = 13, maxTime = 5, forbiddenTime = 50)
public class PassController {

    @GetMapping("/getOne/{id}")
    public Result getOne(@PathVariable("id") Integer id) {
        log.info("执行[pass]-getOne()方法，id为{}", id);
        return Result.SUCCESS();
    }

    /**
     * 表示此接口 3 秒内最大访问次数为 2，禁用时长为 40 秒
     *
     * @return null
     */
    @GetMapping("/get")
    @AccessLimit(second = 3, maxTime = 2, forbiddenTime = 40L)
    public Result get() {
        log.info("执行【pass】-get()方法");
        return Result.SUCCESS();
    }

    /**
     * 表示此接口 20 秒内最大访问次数为 5，禁用时长为 60 秒
     *
     * @return null
     */
    @PostMapping("/post")
    @AccessLimit(second = 20, maxTime = 5, forbiddenTime = 60L)
    public Result post() {
        log.info("执行【pass】-post()方法");
        return Result.SUCCESS();
    }

    @PutMapping("/put")
    public Result put() {
        log.info("执行【pass】-put()方法");
        return Result.SUCCESS();
    }

    @DeleteMapping("/delete")
    public Result delete() {
        log.info("执行【pass】-delete()方法");
        return Result.SUCCESS();
    }
}
